package IOStream.CopyFileDome;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName:Dome001
 * Package:IOStream.CopyFileDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/28-18:49
 * @Version:v1.0
 */
public class Dome001 {
    /*练习：
     * 文件拷贝：把E:\aaa\a.txt拷贝到E:\aaa\bbb文件夹下
     *
     * 注意：选择一个比较下的文件,不要太大
     * */
    public static void main(String[] args) throws IOException, ParseException {
        Date startDate = new Date();
        //创建对象
        FileInputStream fis=new FileInputStream("E:\\aaa\\a.txt");//读
        FileOutputStream fos = new FileOutputStream("E:\\aaa\\bbb\\copy.txt");//写
        //拷贝
        //核心：边读边写
        int b;
        while ((b = fis.read())!=-1){
            fos.write(b);
        }
        //释放资源
        //规则:先开的流最后关闭
        fos.close();
        fis.close();



        Date endDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String date1 = sdf.format(startDate);
        String date2 = sdf.format(endDate);
        long startTime = startDate.getTime();
        System.out.println(startTime);
        long endTime = endDate.getTime();
        System.out.println(endTime);
        long orderTime = endTime - startTime;
        System.out.println(orderTime);
//        long orderTime = orderDate.getTime();

    }


}
/*课堂练习：要统计拷贝时间,单位毫秒*/